import time

from selenium.webdriver.common.by import By
from Base.Base import Base

class Page(Base):
    # 2、在搜索框输入“我喜欢软件测试”，点击搜索，判断是否返回搜素结果，使用PO设计模式进行开发（5分）
    send1_loc = (By.XPATH,'//*[@id="chat-textarea"]')
    def send1(self):
        self.send_keys(self.send1_loc,'我喜欢软件测试')

    cl_bd_loc = (By.XPATH,'//*[@id="chat-submit-button"]')
    def cl_bd(self):
        self.click(self.cl_bd_loc)

    # 3、抓取第一页搜索的所有网站的标题，判断是否包含你的搜索关键字。（5分）
    dy1_loc = (By.XPATH,'//*[@id="1"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def dy1(self):
        return self.get_text(self.dy1_loc)

    dy2_loc = (By.XPATH,'//*[@id="2"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def dy2(self):
        return self.get_text(self.dy2_loc)

    dy3_loc = (By.XPATH,'//*[@id="content_left"]/div[3]/div/div/div[1]/div/div[1]/div/div/h3/div/a')
    def dy3(self):
        return self.get_text(self.dy3_loc)

    dy4_loc = (By.XPATH,'//*[@id="3"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def dy4(self):
        return self.get_text(self.dy4_loc)

    dy5_loc = (By.XPATH,'//*[@id="5"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def dy5(self):
        return self.get_text(self.dy5_loc)

    dy6_loc = (By.XPATH,'//*[@id="6"]/div/div/div/div[1]/div/h3')
    def dy6(self):
        return self.get_text(self.dy6_loc)

    dy7_loc = (By.XPATH,'//*[@id="7"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def dy7(self):
        return self.get_text(self.dy7_loc)

    dy8_loc = (By.XPATH,'//*[@id="8"]/div/div/div/div[1]/div/h3/a/div/div/p')
    def dy8(self):
        return self.get_text(self.dy8_loc)

    dy9_loc = (By.XPATH,'//*[@id="10"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def dy9(self):
        return self.get_text(self.dy9_loc)
    # 翻到第二页，
    two_lco =(By.XPATH,'//*[@id="page"]/div/a[1]/span')
    def two(self):
        self.click(self.two_lco)
    # 4、重复第三个用例（5分）

    to1_loc = (By.XPATH,'//*[@id="11"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to1(self):
        return self.get_text(self.to1_loc)
    to2_loc = (By.XPATH,'//*[@id="12"]/div/div/h3/a')
    def to2(self):
        return self.get_text(self.to2_loc)
    to3_loc = (By.XPATH,'//*[@id="content_left"]/div[3]/div/div/div/div/div[1]/div')
    def to3(self):
        return self.get_text(self.to3_loc)
    to4_loc = (By.XPATH,'//*[@id="13"]/div/div/div/div[1]/div/h3/a')
    def to4(self):
        return self.get_text(self.to4_loc)
    to5_loc = (By.XPATH,'//*[@id="14"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to5(self):
        return self.get_text(self.to5_loc)
    to6_loc = (By.XPATH,'//*[@id="15"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to6(self):
        return self.get_text(self.to6_loc)
    to7_loc = (By.XPATH,'//*[@id="16"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to7(self):
        return self.get_text(self.to7_loc)
    to8_loc = (By.XPATH,'//*[@id="17"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to8(self):
        return self.get_text(self.to8_loc)
    to9_loc = (By.XPATH,'//*[@id="18"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to9(self):
        return self.get_text(self.to9_loc)
    to10_loc = (By.XPATH,'/html/body/div[3]/div[3]/div[1]/div[3]/div[10]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to10(self):
        return self.get_text(self.to10_loc)
    to11_loc = (By.XPATH,'//*[@id="20"]/div/div/div/div[1]/div/h3/a/div/div/p/span/span/span')
    def to11(self):
        return self.get_text(self.to11_loc)

    def baidu_search_001(self):
        # 1、打开百度，判断正确打开（5分）
        self.open_url('https://www.baidu.com/')
        time.sleep(5)
        self.send1()
        self.cl_bd()
        time.sleep(5)
        print(self.dy1())
        try:
            assert '我喜欢软件测试' in self.dy1()
        except Exception as e:
            self.driver.save_screenshot('dy1.png')
        print(self.dy2())
        try:
            assert '我喜欢软件测试' in self.dy2()
        except Exception as e:
            self.driver.save_screenshot('dy2.png')
        print(self.dy3())
        try:
            assert '我喜欢软件测试' in self.dy3()
        except Exception as e:
            self.driver.save_screenshot('dy3.png')
        print(self.dy4())
        try:
            assert '我喜欢软件测试' in self.dy4()
        except Exception as e:
            self.driver.save_screenshot('dy4.png')
        print(self.dy5())
        try:
            assert '我喜欢软件测试' in self.dy5()
        except Exception as e:
            self.driver.save_screenshot('dy5.png')
        print(self.dy6())
        try:
            assert '我喜欢软件测试' in self.dy6()
        except Exception as e:
            self.driver.save_screenshot('dy6.png')
        print(self.dy7())
        try:
            assert '我喜欢软件测试' in self.dy7()
        except Exception as e:
            self.driver.save_screenshot('dy7.png')
        print(self.dy8())
        try:
            assert '我喜欢软件测试' in self.dy8()
        except Exception as e:
            self.driver.save_screenshot('dy8.png')
        print(self.dy9())
        try:
            assert '我喜欢软件测试' in self.dy9()
        except Exception as e:
            self.driver.save_screenshot('dy9.png')
        self.two()
        time.sleep(5)
        print(self.to1())
        try:
            assert '我喜欢软件测试' in self.to1()
        except Exception as e:
            self.driver.save_screenshot('to1.png')
        print(self.to2())
        try:
            assert '我喜欢软件测试' in self.to2()
        except Exception as e:
            self.driver.save_screenshot('to2.png')
        print(self.to3())
        try:
            assert '我喜欢软件测试' in self.to3()
        except Exception as e:
            self.driver.save_screenshot('to3.png')
        print(self.to4())
        try:
            assert '我喜欢软件测试' in self.to4()
        except Exception as e:
            self.driver.save_screenshot('to4.png')
        print(self.to5())
        try:
            assert '我喜欢软件测试' in self.to5()
        except Exception as e:
            self.driver.save_screenshot('to5.png')
        print(self.to6())
        try:
            assert '我喜欢软件测试' in self.to6()
        except Exception as e:
            self.driver.save_screenshot('to6.png')
        print(self.to7())
        try:
            assert '我喜欢软件测试' in self.to7()
        except Exception as e:
            self.driver.save_screenshot('to7.png')
        print(self.to8())
        try:
            assert '我喜欢软件测试' in self.to8()
        except Exception as e:
            self.driver.save_screenshot('to8.png')
        print(self.to9())
        try:
            assert '我喜欢软件测试' in self.to9()
        except Exception as e:
            self.driver.save_screenshot('to9.png')
        print(self.to10())
        try:
            assert '我喜欢软件测试' in self.to10()
        except Exception as e:
            self.driver.save_screenshot('to10.png')
        print(self.to11())
        try:
            assert '我喜欢软件测试' in self.to11()
        except Exception as e:
            self.driver.save_screenshot('to11.png')



